package com.atguigu.tingshu.account.mapper;

import com.atguigu.tingshu.model.account.UserAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

@Mapper
public interface UserAccountMapper extends BaseMapper<UserAccount> {
    @Update("UPDATE user_account SET total_amount=total_amount-#{amount},\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\tavailable_amount = available_amount-#{amount},\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\ttotal_pay_amount = total_pay_amount+#{amount},\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\tupdate_time = NOW()\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\tWHERE user_id = #{userId};")
    Integer checkAndDeduct(@Param("userId") Long userId,@Param("amount") BigDecimal amount);
}
